<%@ page contentType="text/html; charset=UTF-8" language="java"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>取票机管理 </title>
		<%@ include file="/WEB-INF/jspf/taglibs.jspf"%>
		<%@ include file="/WEB-INF/jspf/statics.jspf"%>
</head>
<body>
<div id="wrapper">

    <div class="submit-form pusht">
        <form name="submit-form" id="submit-form" enctype="multipart/form-data">
            <table class="form label-colored-form">
                 <tbody>
                  <tr class="sprite">
                     <td class="label-td" ><label style="width:150px;">是否允许二次进馆：</label></td>
                     <td>
                        <select name="secondeAccess" id="secondeAccess">
                             <option value=1 <c:if test="${invoiceRule.secondeAccess==1}">selected</c:if>>允许</option>
                             <option value=2 <c:if test="${invoiceRule.secondeAccess==2}">selected</c:if>>禁用</option>
                         </select>
                     </td>
                 </tr>
                 <tr class="sprite">
                     <td class="label-td"><label style="width:150px;">进馆时间间隔(小时)：</label></td>
                     <td>
                     	<select name="loginInterval" id="loginInterval">
                             <option value="0.5" <c:if test="${invoiceRule.loginInterval==0.5}">selected</c:if>>30分钟</option>
                             <option value="1" <c:if test="${invoiceRule.loginInterval==1}">selected</c:if>>1小时</option>
                         </select>
                    </td>
                 </tr>
                  <tr class="sprite">
                     <td class="label-td"><label style="width:150px;">取票时间间隔(小时)：</label></td>
                     <td>
                          <select name="invoiceInterval" id="invoiceInterval">
                            <option value="0.5" <c:if test="${invoiceRule.loginInterval==0.5}">selected</c:if>>30分钟</option>
                             <option value="1" <c:if test="${invoiceRule.loginInterval==1}">selected</c:if>>1小时</option>
                         </select>
                     </td>
                 </tr>
                 <tr class="sprite">
                     <td class="label-td"><label style="width:150px;">网上取票：</label></td>
                     <td>
                     	<select name="invoiceOnline" id="invoiceOnline">
                             <option value=1 <c:if test="${invoiceRule.invoiceOnline==1}">selected</c:if>>启用</option>
                             <option value=2 <c:if test="${invoiceRule.invoiceOnline==2}">selected</c:if>>禁用</option>
                         </select>
                       </td>
                 </tr>
                <tr class="sprite">
                     <td class="label-td"><label style="width:150px;">取票上限：</label></td>
                      <td><input type="text" name="maxInvoiceNum" id="maxInvoiceNum" value="${invoiceRule.maxInvoiceNum}" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                 </tr>
                 <tr class="sprite">
                     <td class="label-td"><label style="width:150px;">上限提示信息：</label></td>
                     <td>
                       <textarea name="information" id="information" style="width:380px;height:40px;resize:none; ">${invoiceRule.information }</textarea><span style="color:red;"></span>
                     </td>
                 </tr>
                 <tr class="sprite">
                     <td class="label-td"><label style="width:150px;">服务电话：</label></td>
                     <td><input type="text" name="hotline" id="hotline" value="${invoiceRule.hotline}" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                 </tr>
                 <tr class="sprite">
                     <td class="label-td"><label style="width:150px;">前段退出密码：</label></td>
                      <td><input type="text" name="password" id="password" value="${invoiceRule.password}" maxlength="20" style="width:200px;"><span style="color:red;"></span></td>
                 </tr>
                  <tr class="sprite">
                     <td class="label-td"><label style="width:150px;">备注：</label></td>
                     <td>
                        <textarea name="remark" id="remark" style="width:380px;height:40px;resize:none; ">${invoiceRule.remark }</textarea><span style="color:red;"></span>
                     </td>
                 </tr>
                 <tr class="sprite">
                     <td class="label-td"><label></label></td>
                     <td>
                         <button class="btn btn-primary" id="btn_confirm">保存</button>
                     </td>
                 </tr>
                 </tbody>
            </table>
        </form>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="<%=basePath%>/js/jquery.form.js"></script>
<script type="text/javascript">
  $(document).ready(function () {
      // 给确认按钮绑定点击事件
      $("#btn_confirm").click(function (e) {
          e.preventDefault();
          if(subimtBtn()){
          	dialog_close();
          }
      });
      $("#maxInvoiceNum").focus(function(){
    	  $("#maxInvoiceNum").next().text('');
      });
      $("#hotline").focus(function(){
    	  $("#hotline").next().text('');
      });
  }); 
  function checkForm(){
	  values = $("#submit-form").serializeArray();  
	  var values, index;  
	  var result=true;
	  var isPhone=/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
	  for (index = 0; index < values.length; ++index){  
	    	 if (values[index].name == "maxInvoiceNum"){  
		    	  if(isNaN(values[index].value)){
		    		  result=false;
		    		  $("#maxInvoiceNum").next().text("请输入数字！");
		    		  break;
		    	  }    	  
		      }  
		      if (values[index].name == "hotline"){  
		    	  if(!isPhone.test(values[index].value)){
		    		  result=false;
		    		  $("#hotline").next().text("请输入数字！");
		    		  break;
		    	  }   
		      }
	    }  
	     return result;
  }
  function subimtBtn() {  
	  if(!checkForm()){
		  return false;
	  };
      var form = $("#submit-form");
      var url="${ctx }/equipment/update_invoice_rule"; 
      var options  = {    
          url:url,    
          type:'post',    
          success:function(json)    
          {    
        	 
          }    
      };    
      form.ajaxSubmit(options);  
      dialog_close({callBack: function (data) {
    	  window.parent.invoiceRule();
      }});
  }  
</script>